<template>
  <div id="index">
    <keep-alive>
      <router-view v-if="nav.map((item) => item.route).indexOf($route.name) > -1" class="content-view"></router-view>
    </keep-alive>
    <router-view v-if="nav.map((item) => item.route).indexOf($route.name) < 0" class="content-view"></router-view>
    <van-tabbar route v-model="active" v-show="nav.map((item) => item.route).indexOf($route.name) > -1">
      <van-tabbar-item v-for="item in nav" :key="item.route" replace :to="`/${item.route}`" :icon="item.icon">
        <span>{{ item.name }}</span>
        <template #icon="props">
          <img :src="props.active ? `./img/${ item.route }a.png` : `./img/${ item.route }.png`" 
            style="width: 7vw; height: 7vw;"/>
        </template>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: "index",
  data() {
    return {
      nav: [
        { name: '统计', route: 'Census' },
        { name: '订单', route: 'Order' },
        { name: '商铺', route: 'Shop' },
        { name: '我的', route: 'Mine' }
      ],
      active: "",
    };
  },
  mounted() {
    if (this.$store.getters.ifKefu) {
      this.nav = [
        { name: '统计', route: 'Census' },
        { name: '订单', route: 'Order' },
        { name: '我的', route: 'Mine' }
      ];
    } else if (this.$store.state.userInfo.roleType == 2) {
      this.nav = [
        { name: '统计', route: 'Census' },
        { name: '出入库', route: 'Publicstore' },
        { name: '商铺', route: 'Shop' },
        { name: '我的', route: 'Mine' }
      ];
    } else if (this.$store.state.userInfo.roleType == 3) {
      this.nav = [
        { name: '统计', route: 'Census' },
        { name: '商铺', route: 'Shop' },
        { name: '我的', route: 'Mine' }
      ];
    } else {
      this.nav = [
        { name: '统计', route: 'Census' },
        { name: '订单', route: 'Order' },
        { name: '商铺', route: 'Shop' },
        { name: '我的', route: 'Mine' }
      ];
    }
  }
};
</script>

<style lang="less">
@font-face {
  font-family: "my-icon";
  src: url("/assets/iconfont/iconfont.ttf") format("truetype");
}
#index {
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  font-size: 16px;
  background-color: #f2f2f2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .van-tabbar--fixed {
    position: relative;
  }
  .content-view {
    width: 100%;
    height: 100%;
    flex: 1;
    overflow: auto;
  }
  .page {
    display: flex;
    flex-direction: column;
    background: #f7f8fa;
    width: 100%;
    height: 100%;
    .page-content {
      width: 100%;
      height: 100%;
      flex: 1;
      overflow: auto;
    }
  }
  .form-title {
    margin: 0;
    padding: 16px;
    color: rgba(69, 90, 100, 0.6);
    font-weight: normal;
    font-size: 14px;
    line-height: 16px;
  }
  .form-cell {
    .van-cell:last-child::after {
      display: block;
    }
  }

  .top-picker {
    width: 100%;
    height: 0.8rem;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    padding-left: 0.5rem;
    background: #fff;
    box-sizing: border-box;
  }

  .van-nav-bar .van-icon {
    color: #000;
    font-weight: bold;
    font-size: 18px;
  }
  .van-nav-bar__title {
    color: #000;
    font-weight: bold;
    font-size: 18px;
  }
  .van-tabs__nav--card {
    margin: 0;
    width: 100%;
  }
  .van-tabs__nav--card .van-tab.van-tab--active {
    color: white;
    background-color: #58b99e;
  }
  .van-tabs__nav--card .van-tab {
    color: #58b99e;
    border-right: 1px solid #58b99e;
  }
  .van-tabs__nav--card {
    border-left: 1px solid #58b99e;
    border-bottom: 1px solid #58b99e;
    border-right: 0;
    border-top: 0;
  }
  .van-button {
    border-radius: 0.13rem;
    font-size: 16px;
    font-weight: bold;
  }
  .van-button--info {
    background-image: linear-gradient(-90deg, #1469fe 0%, #2775fd 100%);
    letter-spacing: 0.01rem;
    border-radius: 0.13rem;
  }

  .font-gray {
    color: #6e6e6e;
  }
  .font-black {
    color: #000000;
  }
  .font-warn {
    color: #cb2020;
  }
  .font-red {
    color: #e60012;
  }
  .font-blue {
    color: #4b79f1;
  }
  .font-org {
    color: #e39823;
  }
  .font-green {
    color: #09bb07;
  }


  .list-item {
    width: 100%;
    box-sizing: border-box;
    padding: 0 0.5rem;
    background: #ffffff;
    margin-top: 0.27rem;
    font-size: 12px;
    color: #000000;
    .list-group {
      padding: 0.125rem 0.1rem; 
      border-bottom: 1px solid #ededed;
      box-sizing: border-box;
      &:last-child {
        border: none;
      }
      &.justify {
        .list-row {
          justify-content: space-between;
        }
      }
      &.around {
        .list-row {
          justify-content: space-around;
        }
      }
    }
    .label-text {
      font-size: 12px;
      color: #6e6e6e;
      margin-right: 0.27rem;
    }
    .list-row {
      height: 0.75rem;
      display: flex;
      flex-direction: row;
      align-items: center;
    }
  }

  .flex-row {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .flex-col {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
}

.van-tab__text--ellipsis {
  display: inline !important;
}
</style>
